<?php namespace App\Core\Repository\Criterias;

use App\Core\Repository\Criteria;
use App\Core\Repository\Repository;
use Input;

class PaginateCriteria extends Criteria {
    
    protected $page;
    protected $pageSize;

    public function __construct($currentPage = 'page', $pageSize = 'pageSize') {
        $this->page = intval(Input::get($currentPage, 1));
        $this->pageSize = intval(Input::get($pageSize, 25));
    }

    public function apply(Repository $repository){
        parent::apply($repository);
        $this->query->skip($this->pageSize*($this->page-1))->take($this->pageSize);
    }
}